package indigo.mybatis.dao;

import static java.util.Objects.requireNonNull;

import java.io.Serializable;

public class Order implements Serializable {
	private static final long serialVersionUID = 5154243791250585442L;

	private final String property;
	private final boolean ascending;

	public Order(String property, boolean ascending) {
		this.property = requireNonNull(property, "property cannot be null");
		this.ascending = ascending;
	}

	public String getProperty() {
		return property;
	}

	public boolean isAscending() {
		return ascending;
	}

	@Override
	public String toString() {
		return String.format("Order {property=%s, asending=%s}", property, ascending);
	}

	public static Order asc(String property) {
		return new Order(property, true);
	}

	public static Order desc(String property) {
		return new Order(property, false);
	}
}
